Source for file SC_Image.php
Documentation is available at SC_Image.php
* This file is part of EC-CUBE
* Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
* http://www.lockon.co.jp/
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//---- アップロードファイル加工クラス(thumb.phpとセットで使用する)
if (!ereg("/$", $tmp_dir)) {
//--- 一時ファイル生成(サムネイル画像生成用)
$newFileName = ereg_replace("^.*\.",$mainname, $_FILES[$keyname]['name']);
$result = $this->MakeThumb($_FILES[$keyname]['tmp_name'], $this->tmp_dir , $max_width, $max_height, $newFileName);
GC_Utils_Ex::gfDebugLog($result);
// コピー元ファイル、コピー先ディレクトリが存在する場合にのみ実行する
$from_path = $this->tmp_dir. $filename;
$to_path = $save_dir. "/". $filename;
if (copy($from_path , $to_path)) {
GC_Utils_Ex::gfDebugLog($from_path. "->". $to_path. "のcopyに失敗しました。");
* @param string $FromImgPath ファイル名までのパス
* @param string $ToImgPath 出力先パス
* @param integer $tmpMW 最大横幅
* @param integer $tmpMH 最大縦幅
* @param integer $newFileName 新ファイル名
* @param array 新ファイル名を格納した配列
function MakeThumb($FromImgPath , $ToImgPath , $tmpMW , $tmpMH, $newFileName = ''){
$ThmMaxWidth = LARGE_IMAGE_WIDTH;
$ThmMaxHeight = LARGE_IMAGE_HEIGHT;
$array_ext = explode(".", $FromImgPath);
$ext = $array_ext[count($array_ext) - 1];
if ($tmpMW) $MW = $tmpMW; // $MWに最大横幅セット
if ($tmpMH) $MH = $tmpMH; // $MHに最大縦幅セット
if (empty($FromImgPath) || empty($ToImgPath)){
return array(0,"出力元画像パス、または出力先フォルダが指定されていません。");
return array(0,"出力元画像が見つかりません。");
$size = @GetImageSize($FromImgPath);
if (!$size[2] || $size[2] > 3){ // 画像の種類が不明 or swf
return array(0,"画像形式がサポートされていません。");
if ($tmp_w > 1 || $tmp_h > 1){
$re_size[1] = $size[1] * $MW / $size[0];
$re_size[1] = $size[1] * $MW / $size[0];
$re_size[0] = $size[0] * $MH / $size[1];
$ToFile = $PreWord. $FromFileName; // 拡張子以外の部分までを作成
$ImgNew = imagecreatetruecolor($re_size[0],$re_size[1]);
if ($tmp_w <= 1 && $tmp_h <= 1){
if (!@copy($FromImgPath , $ToImgPath. $ToFile)) { // エラー処理
return array(0,"ファイルのコピーに失敗しました。");
ImageColorAllocate($ImgNew,255,235,214); //背景色
$black = ImageColorAllocate($ImgNew,0,0,0);
$red = ImageColorAllocate($ImgNew,255,0,0);
Imagestring($ImgNew,4,5,5,"GIF $size[0]x$size[1]", $red);
ImageRectangle ($ImgNew,0,0,($re_size[0]- 1),($re_size[1]- 1), $black);
$TmpPath = $ToImgPath. $ToFile;
@Imagepng($ImgNew,$TmpPath);
return array(0,"画像の出力に失敗しました。");
$ImgDefault = ImageCreateFromJpeg($FromImgPath);
//ImageCopyResized( $ImgNew,$ImgDefault, 0, 0, 0, 0,$re_size[0], $re_size[1],$size[0], $size[1]);
if ($re_size[0] != $size[0] || $re_size[0] != $size[0]) {
ImageCopyResampled( $ImgNew,$ImgDefault, 0, 0, 0, 0,$re_size[0], $re_size[1],$size[0], $size[1]);
GC_Utils_Ex::gfDebugLog($size);
GC_Utils_Ex::gfDebugLog($re_size);
$TmpPath = $ToImgPath. $ToFile;
@ImageJpeg($ImgNew,$TmpPath);
return array(0,"画像の出力に失敗しました。<br>${ImgNew}<br>${TmpPath}");
$ImgDefault = ImageCreateFromPNG($FromImgPath);
//ImageCopyResized($ImgNew, $ImgDefault, 0, 0, 0, 0,$re_size[0], $re_size[1],$size[0], $size[1]);
ImageCopyResampled($ImgNew, $ImgDefault, 0, 0, 0, 0,$re_size[0], $re_size[1],$size[0], $size[1]);
$TmpPath = $ToImgPath. $ToFile;
@ImagePNG($ImgNew,$TmpPath );
return array(0,"画像の出力に失敗しました。");
ImageDestroy($ImgDefault);
Documentation generated on Fri, 24 Feb 2012 14:02:49 +0900 by Seasoft
|